package com.cx.controller;

import com.cx.domain.user;
import com.cx.service.userservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
@Controller
public class register {
    @Autowired
    private userservice userservice;
    @RequestMapping("/register.do")
    @ResponseBody
    private String register(@RequestBody List<String> user){
        if(userservice.selectname(user.get(0))!=null){
            return "User already exists";
        }
        System.out.println(userservice.selectname(user.get(0)));
        userservice.insertuser(user.get(0),user.get(1));
        return "success";
    }
    @RequestMapping("/checkname.do")
    @ResponseBody
    private String checkname(@RequestBody List<String> name){
        if(userservice.selectname(name.get(0))!=null){
            return null;
        }
        return "success";
    }

}
